package oojo.data.spec;

import java.util.Set;
import java.util.LinkedHashSet;
import java.util.Collections;

import oojo.data.DataPage;
import oojo.data.Query;

/**
 * List all entities. 
 */
public class Fetch<E> implements Query<E, DataPage<E>> {

    private Set<String> joins;
    private Filter filter;
    private String order;
    private int offset;
    private int limit;
    
    public Fetch() {}
    
    public Fetch(int offset, int limit, String order, Filter filter, String... joins) {
        setOffset(offset);
        setLimit(limit);
        setOrder(order);
        setFilter(filter);
        Collections.addAll(getJoins(), joins);
    }
    
    /**
     * The relations that should be initialized.
     */
    public Set<String> getJoins() {
        if (joins == null) {
            joins = new LinkedHashSet<String>();
        }
        
        return joins;
    }
    
    public void setJoins(Set<String> joins) {
        this.joins = joins;
    }
    
    /**
     * Custom filter criteria.
     */
    public Filter getFilter() {
        return filter;
    }
    
    public void setFilter(Filter filter) {
        this.filter = filter;
    }
    
    /**
     * The order-by property names and direction.
     */
    public String getOrder() {
        return order;
    }
    
    public void setOrder(String order) {
        this.order = order;
    }
    
    /**
     * The page starting index.
     */
    public int getOffset() {
        return offset;
    }
    
    public void setOffset(int offset) {
        this.offset = offset;
    }
    
    /**
     * The page size.
     */
    public int getLimit() {
        return limit;
    }
    
    public void setLimit(int limit) {
        this.limit = limit;
    }
}
